const request = (url, showLoading, options) => {
  return new Promise((resolve) => {
    showLoading && wx.showLoading({
      title: '加载中',
      mask: true
    });
    
    let header = {
      'Content-Type': 'application/json; charset=UTF-8',
    };

    wx.request({
      url: url,
      method: options.method,
      data: options.data,
      header: header,
      success(res) {
        showLoading && wx.hideLoading()
        resolve(res.data)
      },
      fail(error) {
        reject(error)
        wx.showToast({
          title: error.errMsg,
          icon: 'none'
        });
      }
    })
  })
}

export default request;